package com.example.demo2.config;

import com.innover.activemq.consumer.ConsumerOnMessage;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import javax.jms.BytesMessage;
import javax.jms.JMSException;

/**
 * Created by James on 8/9/2017.
 */
@Component
@ComponentScan(value = "com.innover.activemq")
public class MqConfig implements ConsumerOnMessage {

    @Override
    public void processMessage(BytesMessage message) {
        if (message instanceof BytesMessage){
            byte[] b = new byte[2];
            int len;
            BytesMessage bm = message;
            try {
                while ((len = bm.readBytes(b)) != -1) {
                    System.out.println("----Receive----");
                    System.out.println(new String(b, 0, len));
                    System.out.println("========");
                }
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }
}